package com.shopx.base.service.base;

import com.shopx.base.exception.OriginException;
import com.shopx.core.common.CommonConstant;
import com.shopx.core.context.ShopxContext;
import com.shopx.dal.redis.CacheServiceFactory;

/**
 * TODO
 *
 * @author lituo
 * @date 2021/12/5 3:29 PM
 */
public class BaseService {


  /**
   * 获取管理平台登录用户编号
   *
   * @param
   * @return java.lang.String
   * @author lituo
   * @date 3:31 PM 2021/12/5
   */
  protected String getLoginUserId() {
    ShopxContext ctx = ShopxContext.getCurrentContext();
    String userId = (String)ctx.getProperty(CommonConstant.USER_ID);
    return userId;
  }

  /**
   * 获取管理登录用户的企业编号
   *
   * @param
   * @return java.lang.String
   * @author lituo
   * @date 9:22 PM 2021/12/12
   */
  protected String getUserCpId() {
//    if(CacheServiceFactory.getCacheService().get("CP:"+getLoginUserId())!=null){
//      String cpId = (String)CacheServiceFactory.getCacheService().get("CP:"+getLoginUserId());
//      return cpId;
//    }else{
//      throw new OriginException("获取用户所在公司信息失败，请重新登陆");
//    }
    ShopxContext ctx = ShopxContext.getCurrentContext();
    String cpId = (String)ctx.getProperty(CommonConstant.CP_ID);
    return cpId;
  }

  /**
   * @descript 获取日志编号
   *
   * @author lituo
   * @date 2022/3/3 16:41
   * @return java.lang.String
   */
  protected String getTraceId() {
    ShopxContext ctx = ShopxContext.getCurrentContext();
    String traceId = (String)ctx.getProperty(CommonConstant.TRACE_ID);
    return traceId;
  }
}
